<template>
  <div class="container">
    <van-nav-bar fixed title="登录" @click-left="$router.back()" left-arrow />

    <div class="logo-txt">优点达资讯</div>
    <van-form @submit="onSubmit" label-width="50px">
      <van-field
        v-model="username"
        name="mobile"
        label="用户名"
        placeholder="请输入手机号"
        left-icon="manager"
        :rules="[
          { required: true, message: '请填写用户名' },
          {
            pattern: /^(?:(?:\+|00)86)?1[3-9]\d{9}$/,
            message: '请输入正确手机号'
          }
        ]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        left-icon="lock"
        :rules="[
          { required: true, message: '请填写密码' },
          { pattern: /^\w{6,12}$/, message: '请输入6-12位数字,字母,下划线' }
        ]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
    <van-row type="flex" justify="end">
      <van-col :span="10">
        <router-link to="/reg">没有账号,立即注册</router-link>
      </van-col>
    </van-row>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        username: '',
        password: ''
      }
    },
    methods: {
      async onSubmit(values) {
        try {
        const res =  await this.$store.dispatch('login/loginSubmit', values)
        //  console.log(res);
         if(res.message === "登录成功"){
            this.$router.push('/')
         }
        

        } catch (error) {
          // console.log()
        }
      }
    }
  }
</script>

<style scoped>
  .logo-txt {
    text-align: center;
    font-size: 60px;
    margin: 60px auto;
    color: #1989fa;
  }
</style>
